"""
开放商户 - 账单服务

@author liaochangyi
@since 2025-01-25
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.bill.bill_download_query import BillDownloadQueryRequest, BillDownloadQueryResponse
from jlpay.model.openmerch.bill.order_info_query import OrderInfoQueryRequest, OrderInfoQueryResponse
from jlpay.model.openmerch.bill.settle_bill_query import SettleBillQueryRequest, SettleBillQueryResponse


class BillService(BaseService):
    """开放商户账单服务"""
    
    def __init__(self, config):
        """
        初始化账单服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的API_URL
        api_url = getattr(request_class, 'API_URL', '')
        return f"{base_url}{api_url}"
    
    def query_bill_download(self, request: BillDownloadQueryRequest) -> BillDownloadQueryResponse:
        """
        查询账单下载
        
        Args:
            request: BillDownloadQueryRequest实例
            
        Returns:
            BillDownloadQueryResponse: 账单下载查询响应
        """
        return self.post(request, BillDownloadQueryResponse)
    
    def order_info_query(self, request: OrderInfoQueryRequest) -> OrderInfoQueryResponse:
        """
        订单信息查询
        
        Args:
            request: OrderInfoQueryRequest实例
            
        Returns:
            OrderInfoQueryResponse: 订单信息查询响应
        """
        return self.post(request, OrderInfoQueryResponse)
    
    def settle_bill_query(self, request: SettleBillQueryRequest) -> SettleBillQueryResponse:
        """
        结算账单查询
        
        Args:
            request: SettleBillQueryRequest实例
            
        Returns:
            SettleBillQueryResponse: 结算账单查询响应
        """
        return self.post(request, SettleBillQueryResponse) 